cc.Class({
    extends: cc.Component,

    properties: {
        goods1: cc.Prefab,
        goods2: cc.Prefab,
        centent:cc.Node,
        Allshop: cc.SpriteAtlas,

    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start() {

    },
    init(data) {
        let type = data.type;
        switch (type) {
            case 1:
                this.centent.getComponent(cc.Layout).type=cc.Layout.Type.VERTICAL ;
                this.centent.getComponent(cc.Layout).spacingX=50;
                // this.centent.getComponent(cc.Layout).spacingLe=50;
                break;
            case 2:
                this.centent.getComponent(cc.Layout).type=cc.Layout.Type.VERTICAL ;
                this.centent.getComponent(cc.Layout).spacingY=50;

                break;
            case 3:
                let len=data.data.length;
                this.centent.getComponent(cc.Layout).spacingY=50;
                this.centent.getComponent(cc.Layout).spacingX=50;
                this.centent.width=198*Math.ceil(len/2)+(Math.ceil(len/2)-1)*50;

                this.centent.height=500;
                this.centent.getComponent(cc.Layout).type=cc.Layout.Type.GRID ;
                break;
            case 4:
                break;
        }
        this.create_goods(data);
    },
    create_goods(dataArr){
        for(var a=0;a<dataArr.data.length;a++){
            var item;
            if(dataArr.type===2||dataArr.type===3){
                item =cc.instantiate(this.goods2);
            }else {
                item =cc.instantiate(this.goods1);
            }
            item.getComponent("goods").init(dataArr.data[a]);
            item.parent=this.centent;
            console.log(item.width)

        }
        this.node.getComponent(cc.Layout).updateLayout();
        this.node.getChildByName("line").zIndex=100;

    },



    // update (dt) {},
});
